home *** CD-ROM | disk | FTP | other *** search
/ Amiga Collections: Bavarian / Bavarian #088 (19xx)(APS Electronic).zip / Bavarian #088 (19xx)(APS Electronic).adf / initmat.c < prev    next >
C/C++ Source or Header  |  1988-08-03  |  2KB  |  61 lines

  1.  
  2. /**************************************************************
  3. *                                                             *
  4. *  MATRIZENINITIALISIERUNG                                    *
  5. *                                                             *
  6. *  Autor     : MAURER Christian                               *
  7. *  Zweck     : initialisiert Matrix                           *
  8. *  Version   : 1.0:                              24.3.1988    *
  9. *              1.1:                              26.5.1988    *
  10. *                 pointer auf last und next wird NULL         *
  11. *                 zugewiesen.                                 *
  12. *              1.2:                              27.7.1988    *
  13. *                 Datentypen, Fehlerbehandlung                *
  14. *  Kommentar : Das Modul allociert automatisch Speicher       *
  15. *              fuer die Ergebnismatrix, gibt ihm Namen und    *
  16. *              gibt Ergebnismatrix Dimension der Uebergebenen *
  17. *                                                             *
  18. *              cc +fi initmat.c                               *
  19. *                                                             *
  20. ***************************************************************/
  21.  
  22.  
  23. #include <df0:include/exec/types.h>
  24. #include <df0:include/matrix.h>
  25.  
  26. struct matrix *InitMat (a, b_name, name)
  27. struct matrix *a;
  28. UBYTE *b_name, *name;
  29. {
  30.    UBYTE  *strncat(), *strncpy();
  31.    DOUBLE *malloc();
  32.    struct matrix *c;
  33.    SHORT i, strlen();
  34.    VOID KillMat();
  35.  
  36.    c = (struct matrix *) malloc (sizeof (struct matrix));
  37.    if (!c) {
  38.       return (NULL);
  39.    } else {
  40.       c -> zeilen  = a -> zeilen;
  41.       c -> spalten = a -> spalten;
  42.  
  43.       c -> last = NULL;
  44.       c -> next = NULL;
  45.  
  46.       for (i=1; i<=a->zeilen; ++i)
  47.          if ((c->mat[i] = (double *) malloc (8*(a->spalten + 1))) == 0L) {
  48.             c -> zeilen = i - 1;
  49.             KillMat (c);
  50.             return (NULL);
  51.          }
  52.       if (name == 0L) {
  53.          strncpy (c->name, a->name, 15);
  54.          strncat (c->name, b_name, 15-strlen (c->name));
  55.       } else
  56.          strncpy (c->name, name, 15);
  57.  
  58.       return (c);
  59.    }
  60. }
  61.